#ifndef L_VERSION
#   define L_VERSION 1120104
#endif
#include <llib.h>
using namespace llib;

/* Divide leaf into two part (the left and right sub tree),
 * according to the arrangement of complete binary tree.
 * leafNum : the tree leaf number
 * return value: the left sub tree leaf number
 */
Int32 CompleteBinaryTreeLeafDivide(Int32 leafNum)
{
    // the full binary tree case
    if((leafNum & leafNum - 1) == 0) return leafNum / 2;
    // the other (common) case
    int childMax = 1;
    while((childMax << 1) < leafNum) childMax <<= 1;
    int childMin = childMax >> 1;
    int res = leafNum - childMin;
    if(res > childMax) res = childMax;
    return res;
}

class TT {
public:
    void f() const {};
};

struct _S_S {
public:
    Int32 A;
    Int16 B;
    Int64 C;
};


void Test_111215()
{
    const TT t;
    t.f();

    _S_S* pS = new _S_S[2];
    _S_S* pS2 = &(pS[1]);
    Int32 dis = Int32(pS2 - pS);


    Int32 res, leafNum;
    const Int32 loop = 20;
    FOR(I,0,loop) {
        leafNum = (Int32)llib::math::RndRange(3,100);
        res = CompleteBinaryTreeLeafDivide(leafNum);
    }




}
